---------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/clotairemit.edu/Dropbox (MIT)/J-PAL Raskin Transition/10_Analysis&Results/Agent Experiment Analysis/03_
> Logs/20240426_clean_susenas_finance_mar18.log
  log type:  text
 opened on:  26 Apr 2024, 00:06:38

. 
. /*----------------------------------------------------*/
.                 /* Section: Blok 42 */
. /*----------------------------------------------------*/
. 
. ** financial transaction fee
.         u "$importable/blok42_mar_18.dta", clear

.         keep if KODE == 268 | KODE == 287
(11,702,682 observations deleted)

.         gen fin_trans_fees = B42K5 if KODE == 268
(43,021 missing values generated)

.         //summ fin_trans_fees
. 
. ** cell phone/smartphone spending (purchase, repairs, accessories)
.         gen cell_phone_spend = B42K5 if KODE == 287
(115,263 missing values generated)

.         //summ cell_phone_spend
. 
. ** colapse to HH level
.         collapse (sum) fin_trans_fees cell_phone_spend, by(URUT)

.         //summ fin_trans_fees if fin_trans_fees > 0
.         //summ cell_phone_spend if cell_phone_spend > 0
. 
. ** save
.         tempfile blok42

.         save `blok42'
file /var/folders/23/7_md6wbn6ns7m_ppp9yb96sh0000gp/T//S_18300.000001 saved as .dta format

. 
. 
. /*----------------------------------------------------*/
. /* Section 3: Create outcome variables from individual survey */
. /*----------------------------------------------------*/
. 
. u "${importable}/kor18ind_revisi_diseminasi.dta", clear

. 
. 
.         *  Recovering the numnber of small buisnesses in SUESENA 2018 (704-705 in 2019)
. 
.         //tab  R705
.         gen smallbui_sus19_type1_ind_mar18 = R805 == 1

.         replace smallbui_sus19_type1_ind_mar18 = 0 if R804 <= 6 // removing farmers
(52,338 real changes made)

.         replace smallbui_sus19_type1_ind_mar18 = 0 if R804 == 25
(114 real changes made)

.         //summ smallbui_sus19_type1_ind_mar18
. 
.         gen smallbui_sus19_type2_ind_mar18 = R805 == 2

.         replace smallbui_sus19_type2_ind_mar18 = 0 if R804 <= 6
(51,571 real changes made)

.         replace smallbui_sus19_type2_ind_mar18 = 0 if R804 == 25
(12 real changes made)

.         //summ smallbui_sus19_type2_ind_mar18
. 
.         gen smallbui_sus19_type3_ind_mar18 = R805 == 3

.         replace smallbui_sus19_type3_ind_mar18 = 0 if R804 <= 6
(5,936 real changes made)

.         replace smallbui_sus19_type3_ind_mar18 = 0 if R804 == 25
(32 real changes made)

.         //summ smallbui_sus19_type3_ind_mar18
. 
.         gen smallbui_sus19_all_ind_mar18 = smallbui_sus19_type1_ind_mar18

.         replace smallbui_sus19_all_ind_mar18 = 1 if smallbui_sus19_type2_ind_mar18 == 1
(22,454 real changes made)

.         replace smallbui_sus19_all_ind_mar18 = 1 if smallbui_sus19_type2_ind_mar18 == 1
(0 real changes made)

.         //summ smallbui_sus19_all_ind_mar18
. 
. * health complaints
. //tab  R1002
. gen health_complaints_ind = R1002 == 1

. 
. * female head of household
. //tab  R403 R405 if R403 == 1
. gen female_KRT = R403 == 1 & R405 == 2 if R403 == 1
(836,670 missing values generated)

. //summ female_KRT
. 
. * dummy for whether individual has savings account
. //tab  R717
. gen savings_ind = R717 == 1 if R717 != .
(101,524 missing values generated)

. 
. * own cell phone
. //tab  R714
. recode R714 (5 = 0), gen(cell_phone)
(426,330 differences between R714 and cell_phone)

. 
. * use internet
. //tab  R716
. recode R716 (5 = 0), gen(internet_use)
(684,891 differences between R716 and internet_use)

. 
. * Head of household education levels
. //tab  R613
. // School classification descriptions from: https://mikrodata.bps.go.id/mikrodata/index.php/catalog/814/datafile/F1#page=
> F4&tab=data-dictionary
. * Elementary school
. // dummy if hh member has elementary edu or equivalent: (paket A, SDLB, SD, MI)
. gen elementary = inlist(R613, 1, 2, 3, 4) if R403 == 1
(836,670 missing values generated)

. 
. * Junior high school
. // dummy if hh member has junior high edu or equivalent: (paket B, SMPLB, SMP, MTs)
. gen junior_high = inlist(R613, 5, 6, 7, 8) if R403 == 1
(836,670 missing values generated)

. 
. * High school
. // dummy if hh member has high school edu or equivalent, or vocational school: (paket C, SMLB, SMA, MA, SMK, MAK)
. gen high_school = inlist(R613, 9, 10, 11, 12, 13, 14) if R403 == 1
(836,670 missing values generated)

. 
. * Tertiary edu
. // dummy if hh member has tertiary edu: (D1/D2, D3, D4, S1, S2, S3)
. gen tertiary = inlist(R613, 15, 16, 17, 18, 19, 20) if R403 == 1
(836,670 missing values generated)

. //summ elementary junior_high high_school tertiary
. 
. * children
. //summ R407
. gen child = R407 < 18

. 
. ** save individual dataset
. preserve

. keep R101 R102 R105 savings_ind cell_phone internet_use ///
> FWT smallbui_sus19_all_ind_mar18 smallbui_sus19_type1_ind_mar18 ///
> smallbui_sus19_type2_ind_mar18 smallbui_sus19_type3_ind_mar18

. collapse (mean) smallbui_sus19_all_ind_mar18 smallbui_sus19_type1_ind_mar18 ///
> smallbui_sus19_type2_ind_mar18 smallbui_sus19_type3_ind_mar18 savings_ind_mar18 = savings_ind ///
> cell_phone_mar18 = cell_phone internet_use_mar18 = internet_use [aw = FWT], by(R101 R102 R105)

. //summ
. save "$cleaned/finance/susenas_mar18_finance_ind.dta", replace
file /Users/clotairemit.edu/Dropbox (MIT)/J-PAL Raskin Transition/10_Analysis&Results/Agent Experiment
    Analysis/01_Data/cleaned/finance/susenas_mar18_finance_ind.dta saved

. restore

. 
. * collapse number by household
. collapse (sum) smallbui_sus19_all_ind_mar18 smallbui_sus19_type1_ind_mar18 ///
> smallbui_sus19_type2_ind_mar18 smallbui_sus19_type3_ind_mar18 ///
> savings_hh = savings_ind internet_use cell_phone female_KRT elementary ///
> junior_high high_school ///
> tertiary health_complaints = health_complaints_ind children = child, by(URUT)

. 
. * dummy for hh internet use
. di _N
295155

. //summ internet_use
. gen internet_use_hh = internet_use > 0

. drop internet_use

. rename internet_use_hh internet_use

. //tab  internet_use
. 
. * dummy for hh cell phone ownership
. //summ cell_phone
. gen cell_phone_hh = cell_phone > 0

. drop cell_phone

. rename cell_phone_hh cell_phone

. //tab  cell_phone
. 
. * dummy for any health complaints
. gen health_complaint_hh = health_complaints > 0 & health_complaints != .

. //summ health_complaint_hh
. drop health_complaints

. 
. * dummy for any savings account in household
. gen any_savings = savings_hh > 0

. la var any_savings                              "HH member has savings account"

. drop savings_hh

. //summ
. 
.         * Small buism variables = 1 if at least one hh member is part of such business
. 
.         gen smallbui_sus19_all = (smallbui_sus19_all_ind_mar18 >= 1) if smallbui_sus19_all_ind_mar18<.

.         drop smallbui_sus19_all_ind_mar18

. 
.         gen smallbui_sus19_type1 = (smallbui_sus19_type1_ind_mar18 >= 1) if smallbui_sus19_type1_ind_mar18<.

.         drop smallbui_sus19_type1_ind_mar18

. 
.         gen smallbui_sus19_type2 = (smallbui_sus19_type2_ind_mar18 >= 1) if smallbui_sus19_type2_ind_mar18<.

.         drop smallbui_sus19_type2_ind_mar18

. 
.         gen smallbui_sus19_type3 = (smallbui_sus19_type3_ind_mar18 >= 1) if smallbui_sus19_type3_ind_mar18<.

.         drop smallbui_sus19_type3_ind_mar18

. 
. tempfile kor18ind

. qui save `kor18ind'

. 
. /*----------------------------------------------------*/
. /* Section 4: Create variables from household survey */
. /*----------------------------------------------------*/
. 
. // load household survey
. u "${importable}/kor18rt_diseminasi.dta", clear

. 
. * merge in individual data
. merge  1:1  URUT using "`kor18ind'"

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                           295,155  (_merge==3)
    -----------------------------------------

. drop _m

. 
. * merge with blok 42 data
. merge 1:1 URUT using `blok42'

    Result                      Number of obs
    -----------------------------------------
    Not matched                       161,233
        from master                   161,233  (_merge==1)
        from using                          0  (_merge==2)

    Matched                           133,922  (_merge==3)
    -----------------------------------------

. drop _m

. 
. 
. * Merge in kabupaten names (treatment and control districts identified by kabu name, so need name to merge)
. preserve

. import excel "${importable}/province_names.xlsx", firstrow clear
(4 vars, 514 obs)

. rename KodeProvinsi R101

. rename KodeKabupaten R102

. destring R101, replace
R101 already numeric; no replace

. destring R102, replace
R102: all characters numeric; replaced as byte

. rename NamaKabupaten namakabupaten

. rename NamaProvinsi Provinsi

. tempfile kabu_names

. save `kabu_names'
file /var/folders/23/7_md6wbn6ns7m_ppp9yb96sh0000gp/T//S_18300.000005 saved as .dta format

. restore

. 
. merge  m:1 R101 R102 using "`kabu_names'"

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                           295,155  (_merge==3)
    -----------------------------------------

. assert _m != 1

. drop _m

. 
. * dummy for HH receive BPNT
. gen bpnt_ever = R1604 == 1

. 
. * dummy for HH receive Raskin
. gen raskin_any = R1601 == 1

. 
. * dummy for receive any subsidy
. gen receive_subsidy = bpnt_ever == 1 | raskin_any == 1

. //summ receive_subsidy
. 
. * log per capita consumption (monthly)
. //summ EXP_CAP
. gen log_cons = ln(EXP_CAP)

. 
. * per capita consumption, in levels (monthly)
. gen cons = EXP_CAP

. 
. * KKS card
. //tab  R1608
. gen kks = R1608 == 1 | R1608 == 2

. //tab  kks
. 
. * PKH recipient
. //tab  R1609
. recode R1609 (5 = 0), gen(pkh_receipt)
(266,662 differences between R1609 and pkh_receipt)

. //tab  pkh_receipt
. 
. * where to receive PKH benefits
. //tab  R1610C
. gen pkh_post = R1610C == 1 if pkh_receipt == 1
(266,662 missing values generated)

. gen pkh_atm = R1610C == 2 if pkh_receipt == 1
(266,662 missing values generated)

. gen pkh_bank = R1610C == 3 if pkh_receipt == 1
(266,662 missing values generated)

. gen pkh_agent = R1610C == 4 if pkh_receipt == 1
(266,662 missing values generated)

. gen pkh_other = R1610C == 5 if pkh_receipt == 1
(266,662 missing values generated)

. //summ pkh*
. 
. 
.         gen phk_other_location=pkh_bank
(266,662 missing values generated)

.         replace phk_other_location=1 if pkh_post==1
(3,179 real changes made)

.         replace phk_other_location=1 if pkh_atm==1
(9,978 real changes made)

.         replace phk_other_location=1 if pkh_other==1
(5,282 real changes made)

. 
. 
. * any financial transaction fees
. //summ fin_trans_fees
. gen any_fin_trans_fee = fin_trans_fees > 0 & fin_trans_fees != .

. drop fin_trans_fees

. rename any_fin_trans_fee fin_trans_fees

. //tab  fin_trans_fees
. 
. * any cell phone spending
. //summ cell_phone_spend
. gen cell_phone_buy = cell_phone_spend > 0 & cell_phone_spend != .

. //tab  cell_phone_buy
. drop cell_phone_spend

. 
. * receive credit from any source
. //tab  R1701A
. gen credit = R1701A == 1 | R1701B == 1 | R1701C == 1 | R1701D == 1 | R1701E == 1 | ///
>         R1701F == 1 | R1701G == 1 | R1701H == 1 | R1701I == 1 | R1701J == 1

. //tab  credit
. 
. * receive credit from KUR
. gen credit_KUR = R1701A == 1

. //tab  credit_KUR
. 
. * receive credit from commercial banks
. gen credit_bank = R1701B == 1

. //tab  credit_bank
. 
. * receive credit from rural credit banks (BPR)
. gen credit_BPR = R1701C == 1

. //tab  credit_BPR
. 
. * receive credit from coop
. gen credit_coop = R1701D == 1

. //tab  credit_coop
. 
. * receive individual loans with interest
. gen credit_loan = R1701E == 1

. //tab  credit_loan
. 
. * receive credit from pawnshops
. gen credit_pawn = R1701F == 1

. //tab  credit_pawn
. 
. * receive credit from leasing companies
. gen credit_lease = R1701G == 1

. //tab  credit_lease
. 
. * receive credit from KUBE
. gen credit_KUBE = R1701H == 1

. //tab  credit_KUBE
. 
. * receive credit from village owned enterprises
. gen credit_BUMDES = R1701I == 1

. //tab  credit_BUMDES
. 
. * receve credit from other source
. gen credit_other = R1701J == 1

. //tab  credit_other
. 
. * receive social assistance from local govt
. //tab  R1611
. gen local_gov_aid = R1611 == 1

. 
. * amount of social assistance from local govt received
. //summ R1612A_* R1612B_I
. egen local_aid_rp = rowtotal(R1612A_* R1612B_I)

. // bysort local_gov_aid: summ local_aid_rp
. 
. * num HH members
. gen num_in_hh = R301

. 
. 
. 
. /*----------------------------------------------------*/
.                 /* Section: Outliers */
. /*----------------------------------------------------*/
. 
. local continuous_vars "local_aid_rp"

. 
. ** windsorize to 0.5 and 99.5 percentiles of continuous variables
.         foreach var of varlist `continuous_vars' {
  2.                 _pctile `var', p(0.5 99.5)
  3.                 qui gen `var'W = `var'
  4.                 replace `var'W = `r(r1)' if `var' < `r(r1)'
  5.                 replace `var'W = `r(r2)' if `var' > `r(r2)' & `var' != .
  6.                 summ `var' `var'W
  7.         }
(0 real changes made)
(1,188 real changes made)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
local_aid_rp |    295,155    31437.09    291387.3          0   1.72e+07
local_aid_~W |    295,155    25317.52    193453.9          0    2000000

. 
. ** Remove outliers with z-scores of 12 and above
.         * Tag outliers with z-scores 12 and above
.         foreach var of varlist `continuous_vars' {
  2.           qui summ `var'
  3.           qui gen `var'_z = abs((`var' - `r(mean)') / `r(sd)')
  4.           // extremes `var'_z `var', n(20) high
.           quietly count if `var'_z >= 12 & `var'_z != .
  5.           di "`var' has `r(N)' values greater than 12 sd from the mean"
  6.           qui gen `var'_tag = 1 if `var'_z >= 12 & `var'_z != .
  7.         }
local_aid_rp has 305 values greater than 12 sd from the mean

. 
.         * set tagged values to missing
.         // for now: strictly set all 12> to missing
.         foreach var of varlist `continuous_vars' {
  2.                 quietly count if `var'_tag == 1
  3. 
.                 // if tagged vals in var
.                 if `r(N)' > 0 {
  4.                         // copy original variable
.                         quietly gen `var'_orig = `var'
  5. 
.                         // set tagged values to missing
.                   quietly replace `var' = . if `var'_tag == 1
  6.                         local num_miss = `r(N)'
  7.                         di "`num_miss' values in `var' set to missing"
  8.                         extremes `var'_z `var'_orig `var', n(`num_miss')  high
  9.                 }
 10.         }
305 values in local_aid_rp set to missing

  +------------------------------------------+
  |    obs:   local_~z   local~ig   local_~p |
  |------------------------------------------|
  | 252701.   12.07521    3550000          . |
  |    726.   12.24681    3600000          . |
  |   3861.   12.24681    3600000          . |
  |   4713.   12.24681    3600000          . |
  |   9655.   12.24681    3600000          . |
  |------------------------------------------|
  |  10298.   12.24681    3600000          . |
  |  39161.   12.24681    3600000          . |
  |  86809.   12.24681    3600000          . |
  |  89438.   12.24681    3600000          . |
  |  89445.   12.24681    3600000          . |
  |------------------------------------------|
  | 119181.   12.24681    3600000          . |
  | 140975.   12.24681    3600000          . |
  | 161350.   12.24681    3600000          . |
  | 194492.   12.24681    3600000          . |
  | 221375.   12.24681    3600000          . |
  |------------------------------------------|
  | 232170.   12.24681    3600000          . |
  | 246495.   12.24681    3600000          . |
  | 246510.   12.24681    3600000          . |
  | 246514.   12.24681    3600000          . |
  | 246521.   12.24681    3600000          . |
  |------------------------------------------|
  | 246554.   12.24681    3600000          . |
  | 246595.   12.24681    3600000          . |
  | 246621.   12.24681    3600000          . |
  | 246626.   12.24681    3600000          . |
  | 253007.   12.24681    3600000          . |
  |------------------------------------------|
  | 103093.   12.38408    3640000          . |
  | 119168.   12.58999    3700000          . |
  | 122939.   12.58999    3700000          . |
  | 172657.   12.65863    3720000          . |
  |  89038.   12.69295    3730000          . |
  |------------------------------------------|
  |  80874.   12.76158    3750000          . |
  | 178913.   12.76158    3750000          . |
  |   9795.   12.93318    3800000          . |
  |  83164.   12.93318    3800000          . |
  |  89751.   13.07045    3840000          . |
  |------------------------------------------|
  | 133806.   13.10477    3850000          . |
  |  67826.   13.27636    3900000          . |
  | 184049.   13.55091    3980000          . |
  |   5624.   13.61955    4000000          . |
  |   9773.   13.61955    4000000          . |
  |------------------------------------------|
  |   9777.   13.61955    4000000          . |
  |   9791.   13.61955    4000000          . |
  |   9792.   13.61955    4000000          . |
  |   9793.   13.61955    4000000          . |
  |   9798.   13.61955    4000000          . |
  |------------------------------------------|
  |   9803.   13.61955    4000000          . |
  |   9813.   13.61955    4000000          . |
  |   9818.   13.61955    4000000          . |
  |   9819.   13.61955    4000000          . |
  |   9824.   13.61955    4000000          . |
  |------------------------------------------|
  |   9829.   13.61955    4000000          . |
  |   9832.   13.61955    4000000          . |
  |   9835.   13.61955    4000000          . |
  |   9872.   13.61955    4000000          . |
  |   9888.   13.61955    4000000          . |
  |------------------------------------------|
  |   9891.   13.61955    4000000          . |
  |   9906.   13.61955    4000000          . |
  |   9908.   13.61955    4000000          . |
  |   9910.   13.61955    4000000          . |
  |   9911.   13.61955    4000000          . |
  |------------------------------------------|
  |   9912.   13.61955    4000000          . |
  |   9925.   13.61955    4000000          . |
  |   9931.   13.61955    4000000          . |
  |   9948.   13.61955    4000000          . |
  |   9950.   13.61955    4000000          . |
  |------------------------------------------|
  |   9968.   13.61955    4000000          . |
  |   9970.   13.61955    4000000          . |
  |   9975.   13.61955    4000000          . |
  |   9976.   13.61955    4000000          . |
  |   9977.   13.61955    4000000          . |
  |------------------------------------------|
  |   9985.   13.61955    4000000          . |
  |   9987.   13.61955    4000000          . |
  |   9990.   13.61955    4000000          . |
  |  10009.   13.61955    4000000          . |
  |  10015.   13.61955    4000000          . |
  |------------------------------------------|
  |  10021.   13.61955    4000000          . |
  |  10027.   13.61955    4000000          . |
  |  10044.   13.61955    4000000          . |
  |  10045.   13.61955    4000000          . |
  |  31974.   13.61955    4000000          . |
  |------------------------------------------|
  |  77366.   13.61955    4000000          . |
  |  81104.   13.61955    4000000          . |
  | 144208.   13.61955    4000000          . |
  | 162795.   13.61955    4000000          . |
  | 178885.   13.61955    4000000          . |
  |------------------------------------------|
  | 184054.   13.61955    4000000          . |
  | 191051.   13.61955    4000000          . |
  | 191052.   13.61955    4000000          . |
  | 207996.   13.61955    4000000          . |
  | 230222.   13.61955    4000000          . |
  |------------------------------------------|
  | 283616.   13.61955    4000000          . |
  | 283626.   13.61955    4000000          . |
  | 284034.   13.61955    4000000          . |
  | 284514.   13.61955    4000000          . |
  | 291796.   13.61955    4000000          . |
  |------------------------------------------|
  |  96672.   13.70191    4024000          . |
  |  89139.   13.82546    4060000          . |
  | 267842.   13.88723    4078000          . |
  | 252698.   13.96273    4100000          . |
  |  89372.   14.06569    4130000          . |
  |------------------------------------------|
  |   9506.   14.13433    4150000          . |
  |   7030.   14.30592    4200000          . |
  |  74902.   14.30592    4200000          . |
  |  89369.   14.30592    4200000          . |
  |   9870.   14.34024    4210000          . |
  |------------------------------------------|
  |   9867.   14.47751    4250000          . |
  |  88924.   14.71774    4320000          . |
  |  89033.   14.71774    4320000          . |
  | 238597.   14.71774    4320000          . |
  | 281666.   14.92365    4380000          . |
  |------------------------------------------|
  |  15615.   14.99229    4400000          . |
  |  89200.   14.99229    4400000          . |
  |   6051.   15.28057    4484000          . |
  |  39580.   15.33548    4500000          . |
  |  89166.   15.33548    4500000          . |
  |------------------------------------------|
  | 115149.   15.33548    4500000          . |
  | 144139.   15.33548    4500000          . |
  | 177417.   15.33548    4500000          . |
  | 191053.   15.33548    4500000          . |
  | 245581.   15.33548    4500000          . |
  |------------------------------------------|
  | 246502.   15.33548    4500000          . |
  | 283613.   15.33548    4500000          . |
  | 283735.   15.33548    4500000          . |
  | 267973.   15.45902    4536000          . |
  | 272639.   15.52766    4556000          . |
  |------------------------------------------|
  | 210828.   15.67866    4600000          . |
  | 258490.   15.91889    4670000          . |
  |   1665.   16.02185    4700000          . |
  | 103555.   16.02185    4700000          . |
  |   4793.   16.36504    4800000          . |
  |------------------------------------------|
  |   6200.   16.36504    4800000          . |
  |  10260.   16.36504    4800000          . |
  |  89141.   16.36504    4800000          . |
  |  89142.   16.36504    4800000          . |
  |  89143.   16.36504    4800000          . |
  |------------------------------------------|
  |  89146.   16.36504    4800000          . |
  |  89292.   16.36504    4800000          . |
  |  89443.   16.36504    4800000          . |
  |  89481.   16.36504    4800000          . |
  |  89482.   16.36504    4800000          . |
  |------------------------------------------|
  |  89533.   16.36504    4800000          . |
  | 189461.   16.36504    4800000          . |
  | 202432.   16.53663    4850000          . |
  |  37441.   16.77686    4920000          . |
  |   9850.   16.87981    4950000          . |
  |------------------------------------------|
  |   2194.   17.05141    5000000          . |
  |  52816.   17.05141    5000000          . |
  |  74697.   17.05141    5000000          . |
  | 140245.   17.05141    5000000          . |
  | 140652.   17.05141    5000000          . |
  |------------------------------------------|
  | 190785.   17.05141    5000000          . |
  | 202293.   17.05141    5000000          . |
  | 226386.   17.05141    5000000          . |
  | 272494.   17.05141    5000000          . |
  | 283612.   17.05141    5000000          . |
  |------------------------------------------|
  | 283628.   17.05141    5000000          . |
  | 284677.   17.05141    5000000          . |
  | 140346.   17.73778    5200000          . |
  |  89738.   18.01233    5280000          . |
  |  10302.   18.28688    5360000          . |
  |------------------------------------------|
  |  83017.   18.42415    5400000          . |
  |  89437.   18.42415    5400000          . |
  | 198439.   18.42415    5400000          . |
  | 221520.   18.42415    5400000          . |
  | 231023.   18.42415    5400000          . |
  |------------------------------------------|
  |   9796.   18.76734    5500000          . |
  |  15311.   18.76734    5500000          . |
  | 135668.   18.76734    5500000          . |
  | 193496.   18.76734    5500000          . |
  | 239628.   18.76734    5500000          . |
  |------------------------------------------|
  | 283701.   18.76734    5500000          . |
  | 105787.   19.04189    5580000          . |
  |  88258.   19.11052    5600000          . |
  |  89736.   19.45371    5700000          . |
  | 197500.   19.64246    5755000          . |
  |------------------------------------------|
  |  28431.   19.79689    5800000          . |
  |  47313.   20.14008    5900000          . |
  |   9775.   20.48327    6000000          . |
  |   9804.   20.48327    6000000          . |
  |   9815.   20.48327    6000000          . |
  |------------------------------------------|
  |   9889.   20.48327    6000000          . |
  |   9897.   20.48327    6000000          . |
  |   9934.   20.48327    6000000          . |
  |   9944.   20.48327    6000000          . |
  |   9955.   20.48327    6000000          . |
  |------------------------------------------|
  |   9960.   20.48327    6000000          . |
  |   9982.   20.48327    6000000          . |
  |  10007.   20.48327    6000000          . |
  |  10012.   20.48327    6000000          . |
  |  10038.   20.48327    6000000          . |
  |------------------------------------------|
  |  15725.   20.48327    6000000          . |
  |  18370.   20.48327    6000000          . |
  |  50529.   20.48327    6000000          . |
  |  50530.   20.48327    6000000          . |
  |  50531.   20.48327    6000000          . |
  |------------------------------------------|
  |  50909.   20.48327    6000000          . |
  |  88498.   20.48327    6000000          . |
  |  89283.   20.48327    6000000          . |
  | 101113.   20.48327    6000000          . |
  | 117674.   20.48327    6000000          . |
  |------------------------------------------|
  | 194495.   20.48327    6000000          . |
  | 201431.   20.48327    6000000          . |
  | 201434.   20.48327    6000000          . |
  | 235995.   20.48327    6000000          . |
  | 265205.   20.48327    6000000          . |
  |------------------------------------------|
  | 272198.   20.48327    6000000          . |
  | 291244.   20.48327    6000000          . |
  |   9866.   20.82645    6100000          . |
  |  89275.   20.82645    6100000          . |
  |  89041.   21.61578    6330000          . |
  |------------------------------------------|
  |   9962.   22.13056    6480000          . |
  |  15343.    22.1992    6500000          . |
  |  15551.    22.1992    6500000          . |
  |  15579.    22.1992    6500000          . |
  |  15586.    22.1992    6500000          . |
  |------------------------------------------|
  | 189664.    22.1992    6500000          . |
  | 267942.    22.1992    6500000          . |
  |   9839.   22.40511    6560000          . |
  |   9772.   22.54238    6600000          . |
  | 203090.   22.54238    6600000          . |
  |------------------------------------------|
  | 123412.   22.88557    6700000          . |
  | 276746.   23.05716    6750000          . |
  |  33852.   23.22875    6800000          . |
  |  86157.   23.22875    6800000          . |
  |  89267.   23.33171    6830000          . |
  |------------------------------------------|
  |  89272.   23.33171    6830000          . |
  |  15336.   23.91512    7000000          . |
  | 118563.   23.91512    7000000          . |
  | 140721.   23.91512    7000000          . |
  | 190933.   23.91512    7000000          . |
  |------------------------------------------|
  | 236926.   23.91512    7000000          . |
  | 237116.   23.91512    7000000          . |
  | 255833.   23.91512    7000000          . |
  | 276749.   23.91512    7000000          . |
  | 277337.   23.91512    7000000          . |
  |------------------------------------------|
  | 218687.    24.6015    7200000          . |
  | 246516.    24.6015    7200000          . |
  | 144122.   25.28787    7400000          . |
  | 113385.   25.63106    7500000          . |
  | 196246.   25.63106    7500000          . |
  |------------------------------------------|
  | 196247.   25.63106    7500000          . |
  |   9902.   25.97424    7600000          . |
  |  89153.   26.04288    7620000          . |
  | 283703.   26.66061    7800000          . |
  |   9781.   27.34698    8000000          . |
  |------------------------------------------|
  |   9805.   27.34698    8000000          . |
  |   9854.   27.34698    8000000          . |
  |  10014.   27.34698    8000000          . |
  | 119690.   27.34698    8000000          . |
  | 226384.   27.34698    8000000          . |
  |------------------------------------------|
  | 246509.   27.34698    8000000          . |
  |  89645.   27.79313    8130000          . |
  | 143848.   28.71973    8400000          . |
  |  89315.   28.99428    8480000          . |
  | 196249.   29.06291    8500000          . |
  |------------------------------------------|
  | 196245.   29.74929    8700000          . |
  | 112894.   30.43566    8900000          . |
  |  10659.   30.77884    9000000          . |
  | 119743.   30.77884    9000000          . |
  | 196244.   30.77884    9000000          . |
  |------------------------------------------|
  | 140459.   31.46522    9200000          . |
  | 251831.   31.46522    9200000          . |
  |  64055.   33.86752    9900000          . |
  |  96333.   33.86752    9900000          . |
  | 107909.   33.86752    9900000          . |
  |------------------------------------------|
  | 118631.   33.86752    9900000          . |
  | 118796.   33.86752    9900000          . |
  | 119254.   33.86752    9900000          . |
  | 119531.   33.86752    9900000          . |
  | 119533.   33.86752    9900000          . |
  |------------------------------------------|
  | 119688.   33.86752    9900000          . |
  | 131488.   33.86752    9900000          . |
  | 131778.   33.86752    9900000          . |
  | 131780.   33.86752    9900000          . |
  | 132308.   33.86752    9900000          . |
  |------------------------------------------|
  | 137010.   33.86752    9900000          . |
  | 140641.   33.86752    9900000          . |
  | 140713.   33.86752    9900000          . |
  | 140744.   33.86752    9900000          . |
  | 140775.   33.86752    9900000          . |
  |------------------------------------------|
  | 140923.   33.86752    9900000          . |
  | 140948.   33.86752    9900000          . |
  | 140953.   33.86752    9900000          . |
  | 141040.   33.86752    9900000          . |
  | 141043.   33.86752    9900000          . |
  |------------------------------------------|
  | 141187.   33.86752    9900000          . |
  | 141207.   33.86752    9900000          . |
  | 141298.   33.86752    9900000          . |
  | 141299.   33.86752    9900000          . |
  | 182054.   33.86752    9900000          . |
  |------------------------------------------|
  | 221659.   33.86752    9900000          . |
  | 232282.   33.86752    9900000          . |
  | 248502.   33.86752    9900000          . |
  | 257323.   33.86752    9900000          . |
  | 257326.   33.86752    9900000          . |
  |------------------------------------------|
  | 264702.   33.86752    9900000          . |
  | 276838.   33.86752    9900000          . |
  | 291707.   33.86752    9900000          . |
  | 140348.   40.04486   1.17e+07          . |
  |  86741.   40.52532   1.18e+07          . |
  |------------------------------------------|
  |   9801.   41.07442   1.20e+07          . |
  |   9812.   42.65308   1.25e+07          . |
  | 253800.      51.37   1.50e+07          . |
  | 253803.      51.37   1.50e+07          . |
  |  89734.   58.78281   1.72e+07          . |
  +------------------------------------------+

. 
.         drop *z *tag

.         qui ds *orig

.         di "Original versions of vars with outliers removed: `r(varlist)'"
Original versions of vars with outliers removed: local_aid_rp_orig

. 
.         * label new variables
.         foreach var of varlist *W {
  2.                 local varname = substr("`var'", 1, length("`var'") - 1)
  3.                 local label : var label `varname'
  4.                 la var `var' "`label' (Winsorized)"
  5.         }

. 
.         foreach var of varlist *_orig {
  2.                 local varname = substr("`var'", 1, length("`var'") - 5)
  3.                 local label : var label `varname'
  4.                 la var `var' "`label' (Raw)"
  5.                 local labelnew : var label `var'
  6.         }

. 
. 
. /*----------------------------------------------------*/
.       /* Section: Merge treatment assignments */
. /*----------------------------------------------------*/
. 
. * Merge in treatment and control status variables
. // Load (real) treatment and control status dataset
. preserve

. u "$randomization2/treatments.dta", clear

. keep namaprovinsi namakabupaten treated finalstratum

. rename namaprovinsi Provinsi

. keep if treated != .
(75 observations deleted)

. // Need to create kota/kab variable to distinguish bewteen districts with same name in same province
. /* I identify which districts are experimental using ⁨05_Intervention⁩/01 Impact Evaluation⁩/20190523_Kab Kota Phase Expa
> nsion.xlsx,
>                 which distinguishes between kota and kab for same-name districts. If a district is experimental in the ab
> ove sheet, then I
>                 assume that it corresponds to the district with the same name in the randomization2 file. I then assign k
> ab status to these
>                 districts to match the phase sheet. This distinguishes between districts in the same province with the sa
> me name. */
. gen kab = 1 if inlist(namakabupaten, "BIMA", "GORONTALO", "PEKALONGAN", "SERANG")
(101 missing values generated)

. 
. // rename Kabupaten Pontianak to Mempawah (name change in 2014)
. // Note: Kota Pontianak is A/B district, kabupaten Mempawah/Pontianak is IE district
. replace namakabupaten = "MEMPAWAH" if namakabupaten == "PONTIANAK"
(1 real change made)

. 
. tempfile treatments

. save `treatments'
file /var/folders/23/7_md6wbn6ns7m_ppp9yb96sh0000gp/T//S_18300.000007 saved as .dta format

. restore

. 
. // abbreviate province names to match treatment assignment file
. replace Provinsi = "KEP. BANGKA BELITUNG" if Provinsi == "KEPULAUAN BANGKA BELITUNG"
(3,584 real changes made)

. replace Provinsi = "D I YOGYAKARTA" if Provinsi == "DI YOGYAKARTA"
(3,697 real changes made)

. replace Provinsi = "NTB" if Provinsi == "NUSA TENGGARA BARAT"
(6,261 real changes made)

. 
. // create kab variable to match
. gen kab = 1 if inlist(KABU, 5206, 7502, 3326, 3604)
(292,331 missing values generated)

. 
. // rename KABU_NAME namakabupaten
. merge  m:1 Provinsi namakabupaten kab using "`treatments'"

    Result                      Number of obs
    -----------------------------------------
    Not matched                       229,805
        from master                   229,805  (_merge==1)
        from using                          0  (_merge==2)

    Matched                            65,350  (_merge==3)
    -----------------------------------------

. assert _m != 2

. drop _m

. 
. // dummy for experimental districts
. gen experimental = treated != .

. 
. // assert double named districts properly assigned
. foreach dist of numlist 5272 3279 7571 3375 3673 {
  2.         assert experimental == 0 if KABU == `dist'
  3. }

. foreach dist of numlist 6303 5206 7502 3326 3604 {
  2.         assert experimental == 1 if KABU == `dist'
  3. }

. 
. // save version with full sample
. drop R14* R15* R16* R17* R18* R19* CATATAN NUINFORT*

. //summ
. save "$cleaned/finance/susenas_mar18_finance_hh_full.dta", replace
file /Users/clotairemit.edu/Dropbox (MIT)/J-PAL Raskin Transition/10_Analysis&Results/Agent Experiment
    Analysis/01_Data/cleaned/finance/susenas_mar18_finance_hh_full.dta saved

. cap log close
